using NFreeMarker.Template;

namespace NFreeMarker.Core
{
    internal sealed class BooleanLiteral : Expression
    {
        private readonly bool _val;

        public BooleanLiteral(bool val)
        {
            _val = val;
        }

        internal static ITemplateBooleanModel GetTemplateModel(bool b)
        {
            return b ? TemplateBooleanModel.True : TemplateBooleanModel.False;
        }

        internal override bool IsTrue(Environment env)
        {
            return _val;
        }

        public override string GetCanonicalForm()
        {
            return _val ? "true" : "false";
        }

        public override string ToString()
        {
            return _val ? "true" : "false";
        }

        protected override ITemplateModel _getAsTemplateModel(Environment env)
        {
            return _val ? TemplateBooleanModel.True : TemplateBooleanModel.False;
        }

        internal override bool IsLiteral()
        {
            return true;
        }

        protected override Expression DeepCloneImpl(string name, Expression subst)
        {
            return new BooleanLiteral(_val);
        }
    }
}